package com.farm.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.farm.service.UserService;
import com.farm.utils_all.AuthUtils;
import com.farm.utils_all.Constants;
import com.farm.utils_all.HUtil;
import com.farm.utils_all.IdCardUtil;
import com.farm.utils_all.WXUtil;

import net.sf.json.JSONObject;
@Controller
public class UserController {
	
	@Autowired
	private UserService userService;
	
	@ResponseBody
	@RequestMapping(value ="/requestOpenid.do", produces = { "application/json;charset=UTF-8" })
	public Map<String, Object> userInfo(@RequestParam Map<String, Object> map) {
		System.out.println("创建用户" + map);
		Map<String, Object> maps = new HashMap<String, Object>();//解析openid
		String url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + Constants.APPID + "&secret="
				+ Constants.SecretKey + "&js_code=" + map.get("code") + "&grant_type=authorization_code";
		try {
			JSONObject jsonObject = AuthUtils.doGetJson(url);

			maps = jsonObject;
			//maps.put("openid", "oaUOa5RafKZUwkrqztdJjSq_tKmk");
			//判断是否是正规用户
			
		} catch (Exception e) {   
			e.printStackTrace();
		}
		
		System.out.println(maps.get("openid"));
		return maps;
	}
}
